package com.huifaapp.mall.dialogs;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.huifaapp.mall.R;
import com.huifaapp.mall.view.SlackLoadingView;


/**
 * @author: wangZ
 * @date：2017/8/15 11:57
 * FileName：LoadingDialog
 * @description：LoadingDialog
 */

public class LoadingDialog {

    public static final String KEY_LOADING_TEXT = "LOADING_TEXT";
    SlackLoadingView slLoading;
    TextView loadingText;


    private Context context;
    private Dialog dialog;
    private View view;


    public LoadingDialog(Context context) {
        this.context = context;
        initDialog();

    }

    private void initDialog() {
        view = LayoutInflater.from(context).inflate(R.layout.layout_loading_dialog, null);
        dialog = new Dialog(context, R.style.loading_dialog);
        dialog.setContentView(view);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
//        lp.width = DensityTool.dip2px(context, 100);
//        lp.height = DensityTool.dip2px(context, 100);
        SlackLoadingView loadingView = (SlackLoadingView) view.findViewById(R.id.sl_loading);
//        loadingView.setLayoutParams(
//                new LinearLayout.LayoutParams(DensityTool.dip2px(context, 100) - DensityTool.dip2px(context, 60),
//                        DensityTool.dip2px(context, 100) - DensityTool.dip2px(context, 60)));
        window.setAttributes(lp);

        dialog.setCanceledOnTouchOutside(false);
    }


    public void show() {
        if (dialog != null) {
            dialog.show();
        }

    }

    public void dismiss() {
        if (dialog != null) {
            dialog.dismiss();
        }

    } public void cancel() {
        if (dialog != null) {
            dialog.cancel();
        }

    }

    public void setContent(String text) {
        ((TextView) view.findViewById(R.id.loading_text)).setText(text);

    }

    public boolean isShowing() {
        return dialog.isShowing();

    }


//    @Override
//    public int getstyle() {
//        return R.style.loading_dialog;
//    }
//
//    @Override
//    public int getDialogLayoutId() {
//        return R.layout.layout_loading_dialog;
//    }
//
//    @Override
//    public void initData(Bundle savedInstanceState) {
//
//    }
//
//    @Override
//    public void initView(View view) {
//        if (loadingText != null) {
//            loadingText.setText(getArguments().getString(KEY_LOADING_TEXT));
//        }
//
//    }
//
//    @Override
//    public Dialog getDialog() {
//
//        return super.getDialog();
//    }
//
//    @Override
//    public void handleWindow(Window window) {
//        Window dialogWindow = getDialog().getWindow();
//        dialogWindow.setGravity(Gravity.CENTER);
//        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
////		lp.setWindowAnimations(R.style.dialogWindowAnim); //设置窗口弹出动画
//        dialogWindow.setWindowAnimations(R.style.promptdialog_anim); //设置窗口弹出动画
//        DisplayMetrics d = getActivity().getResources().getDisplayMetrics(); // 获取屏幕宽、高用
////        lp.width = (int) (d.widthPixels * 0.8); // 高度设置为屏幕的0.6
//        dialogWindow.setAttributes(lp);
//    }


}
